<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<% String contextPath = request.getContextPath(); %>
<%@page import="com.infodms.dms.bean.TtAsWrGameBean"%>

<%@page import="com.infodms.dms.util.CommonUtils"%>
<%@page import="java.util.List"%>
<%@page import="com.infodms.dms.po.TtAsWrRulePO"%>
<%@page import="com.infodms.dms.common.Constant"%>
<%@page import="com.infodms.dms.po.TtAsWrGamefeePO"%><html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	    <jsp:include page="${contextPath}/common/jsp_head_new.jsp" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>三包策略明细维护(保养费用、车型和省份)</title>
		<script type="text/javascript">
		    function doInit()
			{
			   loadcalendar();
			}
		</script>
	</head>
<body onload="doInit();">
	<div class="navigation">
  		<img src="<%=contextPath%>/img/nav.gif" />当前位置：售后服务管理&gt;索赔基本数据&gt;三包策略维护
  	</div>
<% 
	TtAsWrGameBean gamePO = (TtAsWrGameBean)request.getAttribute("gamePO");
%>
	<form method="post" action="<%=contextPath%>/claim/basicData/TreeGuaranteesStrategy/updateStrategy.do" name="fm" id="fm">
	    <table border="0" width="100%">
	    <tr>
		    <td>
			    <!-- 三包策略基本信息  -->
				<table class="table_info">
				    <tr>
			           <th colspan="4">
			           	<img class="nav" src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('baseTab')">基本信息</a>
			           </th>
		            </tr>
		        </table>
				<!-- 三包策略基本信息  -->
				<table class="table_edit" id="baseTab">
					<tr>
						<td align="right">三包策略类型：</td>
						<td>
							<script type="text/javascript">
								document.write(getItemValue(<%=gamePO.getGameType()%>));
							</script>
						</td>
						<td align="right">三包策略状态：</td>
						<td>
							<script type="text/javascript">
								 genSelBoxExp("STATUS",<%=Constant.STATUS%>,"<%=CommonUtils.checkNull(gamePO.getGameStatus())%>",false,"short_sel","","false",'');
						    </script>
						</td>
					</tr>
					<tr>
						<td align="right">三包策略代码：</td>
						<td>
							<input type='text' name='STRATEGY_CODE' id='STRATEGY_CODE' 
							class="middle_txt" datatype="0,is_null,20" 
							value="<%=CommonUtils.checkNull(gamePO.getGameCode())%>"/>
						</td>
						<td align="right">三包策略名称：</td>
						<td>
							<input type='text' name='STRATEGY_NAME' id='STRATEGY_NAME'
							class="middle_txt" datatype="0,is_null,60"
							value="<%=CommonUtils.checkNull(gamePO.getGameName())%>"/>
						</td>
					</tr>
				
					<tr>
						<td align="right">免费保养次数：</td>
						<td>
						    <input type='text' name='GUARANTEE_COUNT' id='GUARANTEE_COUNT' onchange="dyncCreateGuarante('dyncGuarantee',this)"
							class="short_txt" datatype="0,isDigit,10"
							value="<%=CommonUtils.checkNull(gamePO.getMaintainNum()) %>"/>
						</td>
						<td align="right">三包规则：</td>
						<td>
						    <select name="GUARANTEE_RULE_ID" id="GUARANTEE_RULE_ID" 
						    	class="long_sel">
							<% 
								List dataList = (List)request.getAttribute("ruleList");
								if(dataList!=null && dataList.size()>0){
							%>
							<%
									for(int i=0;i<dataList.size();i++){
										TtAsWrRulePO rulePO = (TtAsWrRulePO)dataList.get(i);
							%>
									<option value="<%=rulePO.getId()%>" <%=rulePO.getId().equals(gamePO.getRuleId())?"selected":""%>><%=rulePO.getRuleName()%></option>
							<%		}%>
							<% } else { %>
								<option value="">请先维护业务类型三包规则</option>
							<% } %>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">三包策略开始时间：</td>
						<td>
							<input type="text" name="START_TIME" id="START_TIME"
				             value="<%=CommonUtils.checkNull(gamePO.getStartTime())%>" type="text" class="short_txt" 
				             datatype="0,is_date,10" group="START_TIME,END_TIME" 
				             hasbtn="true" callFunction="showcalendar(event, 'START_TIME', false);"/>
						</td>
						<td align="right">三包策略结束时间：</td>
						<td>
							<input type="text" name="END_TIME" id="END_TIME"
					             value="<%=CommonUtils.checkNull(gamePO.getEndTime())%>" type="text" class="short_txt" 
					             datatype="0,is_date,10" group="START_TIME,END_TIME" 
					             hasbtn="true" callFunction="showcalendar(event, 'END_TIME', false);"/>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top">备注：</td>
						<td colspan="3">
							<textarea name="REMARK" rows="3" cols="80"><%=CommonUtils.checkNull(gamePO.getRemark())%></textarea>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<!-- 三包策略对应保养费用信息  -->
			    <table class="table_info" >
			       <tr style="display: none">
			           <th>
			           	<img class="nav" src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('guaranteeTab')">保养费用</a>
			           </th>
		           </tr>
		        </table>
		        <table width="100%" id="guaranteeTab" >
					<tr>
						<td>
							<%
								List amountList = (List)request.getAttribute("amountList");
							    if(amountList!=null && amountList.size()>0){
							    	//将已经设定保养费用隐藏到页面
							    	for(int i=0;i<amountList.size();i++){
							    		TtAsWrGamefeePO feePO = (TtAsWrGamefeePO)amountList.get(i);
							%>
										<input type="hidden" name="HIDEN_GUARANTEE_AMOUNT<%=i%>" id="HIDEN_GUARANTEE_AMOUNT<%=i%>"
						       							value="<%=CommonUtils.checkNull(feePO.getManintainFee())%>"/>
							<%      } %>
							<table class="table_edit" border="0" cellpadding="0" cellspacing="0"  >
							   		<tr >
							   			<td align="center">
							   				<div id="dyncGuarantee">
							   					<table class="table_edit">
									<%
									        //显示已经设定的保养费用（未设定的显示为空）
									    	for(int i=0;i<amountList.size();i=i+2){
									    		TtAsWrGamefeePO feePO = (TtAsWrGamefeePO)amountList.get(i);
									%>
												<tr style="display: none">
								       				<td>第<%=(i+1)%>次保养费用(元)：</td>
								       				<td><input type="text" name="GUARANTEE_AMOUNT<%=i%>" id="GUARANTEE_AMOUNT<%=i%>"
								       							value="<%=CommonUtils.checkNull(feePO.getManintainFee())%>" datatype="0,is_double,20" decimal="2"/>
								       				</td>
								       				<%if((i+1)<amountList.size()) {
								       					TtAsWrGamefeePO feePO2 = (TtAsWrGamefeePO)amountList.get(i+1);
								       				%>
								       				<td>第<%=(i+2)%>次保养费用(元)：</td>
								       				<td><input type="text" name="GUARANTEE_AMOUNT<%=i+1%>" id="GUARANTEE_AMOUNT<%=i+1%>"
								       							value="<%=CommonUtils.checkNull(feePO2.getManintainFee())%>" datatype="0,is_double,20" decimal="2"/>
								       				</td>
								       				<%}else{ %>
								       					<td>&nbsp;</td>
								       					<td>&nbsp;</td>
								       				<%} %>
								       			</tr>
									<%      }%>
									<%  } %>
									&nbsp;
											   </table>
										   </div>
										</td>
								    </tr>
								<tr>
									<td align="center" >
										    <!-- 三包策略ID -->
					       		            <input type="hidden" name="ID" value="<%=gamePO.getId()%>"/>
											<input type="button" name="bt_add" class="normal_btn" 
											     onclick="updateGuaranteeConfirm();" value="修改"/>&nbsp;&nbsp;
											<input type="button" name="bt_back" class="normal_btn" 
											    onclick="historyBack();" value="返回"/>
									</td>
								</tr>
						 	</table>
				        </td>
					</tr>
		        </table>
	        </td>
        </tr>
        <% if(Constant.GAME_TYPE_02.equals(gamePO.getGameType())) {%>
        <tr>
	        <td>
				<!-- 三包策略对应车型维护  -->
			    <table class="table_info" border="0" id="myinfo">
					 <tr>
					   <th>
					    	<img src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('modelTab')">车型列表</a>
					  </th>
					 </tr>
				</table>
				<table width="100%" id="modelTab" style="display:none">	
					<tr>
						<td>
							<iframe frameborder="0" scrolling="yes" style="offsetLeft:0;offsetWidth:0;OVERFLOW:SCROLL;OVERFLOW-Y:HIDDEN" id="carModelFrame"
							 src="<%=contextPath%>/jsp/claim/basicData/guaranteesStrategyModelAdd.jsp?ID=<%=gamePO.getId()%>" name="carModelFrame" width="100%">
							</iframe>
				        </td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<!-- 三包策略对应省份维护  -->
			    <table class="table_info" border="0" id="myinfo">
					 <tr>
					   <th>
					    	<img src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('provinceTab')">省份列表</a>
					  </th>
					 </tr>
				</table>
				<table width="100%" id="provinceTab"  style="display:none">	
					<tr>
						<td>
							<iframe id="proviceFrame" frameborder="0" scrolling="yes" style="offsetLeft:0;offsetWidth:0;OVERFLOW:SCROLL;OVERFLOW-Y:HIDDEN"
							 src="<%=contextPath%>/jsp/claim/basicData/guaranteesStrategyProvinceAdd.jsp?ID=<%=gamePO.getId()%>" name="proviceFrame" width="100%">
							</iframe>
				        </td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<!-- 三包策略对应产地维护  -->
			    <table class="table_info" border="0" id="myinfo">
					 <tr>
					   <th>
					    	<img src="<%=contextPath%>/img/subNav.gif" /><a href="#" onclick="showTab('yieldlyTab')">产地列表</a>
					  </th>
					 </tr>
				</table>
				<table width="100%" id="yieldlyTab"  style="display:none">	
					<tr>
						<td>
							<iframe id="yieldlyFrame" frameborder="0" scrolling="yes" style="offsetLeft:0;offsetWidth:0;OVERFLOW:SCROLL;OVERFLOW-Y:HIDDEN"
							 src="<%=contextPath%>/jsp/claim/basicData/guaranteesStrategyYieldlyAdd.jsp?ID=<%=gamePO.getId()%>" name="proviceFrame" width="100%">
							</iframe>
				        </td>
					</tr>
				</table>
			</td>
		</tr>
		<%} %>
		</table>
	</form>	
	<script type="text/javascript">
	    //控制是否显示TABLE
		function showTab(tableId){
			var tableVar = document.getElementById(tableId);
			var displayContent = tableVar.style.display;
			if(displayContent!='' && displayContent!=null && displayContent=='none'){
				tableVar.style.display = '';
			}else{
				tableVar.style.display = 'none';
			}
		}

		//确认保存保养费用
		function updateGuaranteeConfirm(){
			var remarkValue = $('REMARK').value;
			if(remarkValue && remarkValue.length>500){
				alert("备注信息长度不能超过 500!");
				return;
			}
			if(submitForm('fm')){//查询表单数据格式
				//var nowDate = (new Date()).Format("yyyy-MM-dd");
			    //var startTime = document.getElementById('START_TIME').value;
			    //if(!checkDate(startTime,nowDate)){//选择三包策略开始时间必须大于当前时间    
			        if(confirm("是否确认修改？")){
			        	updateGuarantee();
			        }
					//MyConfirm("是否确认修改？",updateGuarantee,[null]);
			    //}else{
				   // MyAlert("三包策略开始日期必须大于当前日期！");
			    //}
			}
		}

		//保存保修费用
		function updateGuarantee(){
			//makeNomalFormCall('<%=contextPath%>'+'/claim/basicData/TreeGuaranteesStrategy/updateStrategy.do',backDeal,'fm','');
			var frm = document.getElementById('fm');
			frm.submit();
		}

		//保存后处理
		function backDeal(){
			//刷新保修费用
			//guaranteeFrame.window.location.reload();
		}

		function historyBack(){
			if(parent.${'inIframe'}){
				try{
				//location.href='<%=contextPath%>/claim/basicData/TreeGuaranteesStrategy/strategyQueryInit.do';
				parent.window._hide();
				parent.${'inIframe'}.__extQuery__(1);
				}catch(e){
					location.href='<%=contextPath%>/claim/basicData/TreeGuaranteesStrategy/strategyQueryInit.do';
				}
			}else{
				window.close();
			}
		}


		//动态生成保养费用列表
		function dyncCreateGuarante(tbodyId,count){
			var varTbodyId = document.getElementById(tbodyId);
			var guaranteCount = count.value;
			if(varTbodyId!=null && varTbodyId!='undefined'){
				var content = '';
				for(var i=0;i<guaranteCount;i=i+2){
					var setguaranteValue = getHiddenSetGuaranteValue('HIDEN_GUARANTEE_AMOUNT'+i);
					content = content + getDyncContent(i,setguaranteValue);
			        if((i+1)<guaranteCount){
			        	var setguaranteValue2 = getHiddenSetGuaranteValue('HIDEN_GUARANTEE_AMOUNT'+(i+1));
			        	content = content + getDyncContent((i+1),setguaranteValue2);
			        }
					content = "<tr>" + content + "</tr>";
				}
				varTbodyId.innerHTML = '<table class="table_edit">' + content + '</table>';
				for(var i=0;i<guaranteCount;i++){
					setMustStyle([document.getElementById('GUARANTEE_AMOUNT'+i)]);
				}
			}
		}

		function getDyncContent(index,value){
			var content = '<td align="right">第'+(index+1)+'次保养费用(元)：</td>'+
			'<td align="left">'+
				'<input type="text" datatype="0,is_double,20" decimal="2" name="GUARANTEE_AMOUNT'+index+'" id="GUARANTEE_AMOUNT'+index+'"'+' value="'+value+'"/>'+
			'</td>';
			return content;
		}

		//取得已经设定的保养费用
		function getHiddenSetGuaranteValue(inputId){
			var res = '';
			var setguar = document.getElementById(inputId);
			if(setguar!=null && setguar!='undefined')
				res = setguar.value;
			return res;
		}

	</script>
</body>
</html>